package com.sxbbc.bank.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sxbbc.common.basics.exceptions.ThrowJsonException;
import com.sxbbc.common.basics.rest.RestFactory;
import com.sxbbc.common.basics.rest.RestResponse;
import com.sxbbc.common.core.entity.banks.SysProduct;
import com.sxbbc.common.core.entity.banks.SysProductType;
import com.sxbbc.common.core.mapper.banks.SysProductMapper;
import com.sxbbc.bank.service.ISysProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sxbbc.common.core.utils.BasePage;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 产品表 服务实现类
 * </p>
 *
 * @author
 * @since 2020-09-04
 */
@Service
public class SysProductServiceImpl extends ServiceImpl<SysProductMapper, SysProduct> implements ISysProductService {

    private static Logger log = LogManager.getLogger(SysProductServiceImpl.class);

    @Autowired
    private SysProductMapper sysProductMapper;

    @Override
    public RestResponse  selSysProduct(BasePage<SysProduct> page, SysProduct sysProduct, String yyTime) {
        log.info("执行【产品展示】产品列表查询接口");
        log.info("分页参数{size"+page.getSize()+"，current"+page.getCurrent()+"，pages"+page.getPages()+"}");
        log.info("对象"+sysProduct);
        log.info("查询时间"+yyTime);
        QueryWrapper<SysProduct> wrapper = new QueryWrapper<>();
        if(null!=sysProduct){
//            if(StringUtils.isNotEmpty(sysProductType.getProdName())){
//                wrapper.like("prod_name",sysProductType.getProdName());
//            }
//            if(StringUtils.isNotEmpty(sysProductType.getProdCode())){
//                wrapper.like("prod_code",sysProductType.getProdCode());
//            }
//            if (StringUtils.isNotEmpty(sysProductType.getTypeGrade())){
//                wrapper.eq("type_grade",sysProductType.getTypeGrade());
//            }
//            if (null!=sysProductType.getStatus()){
//                wrapper.eq("status",sysProductType.getStatus());
//            }
            if(null!=yyTime && yyTime.trim().length()>0){
                String [] arr=yyTime.split("~");
                wrapper.between("create_time",arr[0],arr[1]);
            }
        }
        super.page(page,wrapper);
        try {
            return RestFactory.success(page.getRecords(), page.getTotal());
        } catch (Exception e) {
            log.error("【产品展示】产品列表查询异常："+e.getMessage());
            throw new ThrowJsonException("列表查询异常");
        }
    }
}
